<template>
	<view class="main-admin bg-admin">
		<view class="login shadow">
			<view class="pic">
				<text class="icon-settingsfill text-blue"></text>
			</view>
			<view class="hint">家政员管理系统</view>

			<view class="form-group margin-top">
				<view class="title">账号：</view>
				<input type="text" placeholder="请输入管理员账号" maxlength="30" v-model="name" />
			</view>

			<view class="form-group">
				<view class="title">密码：</view>
				<input type="password" placeholder="请输入管理员密码" maxlength="30" v-model="pwd" />
			</view>

			<button class="btn bg-admin margin-bottom" @click="bindLoginTap">
				点击登录
			</button>
			<view class="return text-grey" style="margin-top: 20px">本系统仅限于家政员登录</view>
			<view @click="bindBackTap" class="return text-grey" style="cursor: pointer;">
				<text class="icon-back"></text>返回用户端
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import {
		adminLogin,
		addlogin
	} from '@/request/api.js';
	import {
		onLoad,
		onShow
	}
	from '@dcloudio/uni-app';
	let uid = uni.getStorageSync('uid');
	console.log(uid,"uid")
	onLoad(async (e) => {
		if (uid != '') {
			uni.redirectTo({
				url: '/pages/home/index/index'
			});
		}
	});
	const name = ref('');
	const pwd = ref('');

	function bindLoginTap() {
		if (name.value == "" || pwd.value == "") {
			uni.showToast({
				title: '请填写用户名或密码',
				icon: 'none'
			});
			return;
		}
		addlogin({
			name: name.value,
			pwd: pwd.value
		}).then((res) => {
			console.log(res)
			if (res.data.code == 200) {
				uni.setStorageSync('uid', res.data.data.id)
				uni.redirectTo({
					url: '/pages/home/index/index'
				});
			} else {
				uni.showToast({
					title: res.data.msg,
					icon: 'none'
				});
			}
		});

	}

	const bindBackTap = () => {
		uni.switchTab({
		  url: '/pages/user/grzx/grzx'
		});
	}
</script>
<style scoped>
	.main-admin {
		width: 100%;
		min-height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		background-color: #2196F3;
		/* 背景颜色调整为浅灰色 */
	}

	.login {
		/*width: 100%; */
		max-width: 400px;
		/* 最大宽度调整为400px */
		background-color: #ffffff;
		border-radius: 8px;
		/* 边框圆角调整为8px */
		box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
		/* 添加阴影效果 */
		padding: 20px;
		margin-top: 20px;
		/* 调整上边距 */
	}

	.login .hint {
		color: #333333;
		font-weight: bold;
		font-size: 18px;
		text-align: center;
		margin-bottom: 20px;
		/* 添加下边距 */
	}

	.form-group {
		margin-bottom: 15px;
		/* 添加下边距 */
	}

	.form-group .title {
		color: #666666;
		margin-bottom: 5px;
		/* 添加下边距 */
	}

	input {
		border: 1px solid #dddddd;
		border-radius: 4px;
		padding: 10px;
		/*width: 100%;*/
	}

	button {
		background-color: #2196F3;
		/* 按钮背景颜色调整为绿色 */
		color: #ffffff;
		font-size: 16px;
		border: none;
		border-radius: 4px;
		/*padding: 5px; */
		width: 100%;
		margin-top: 20px;
		/* 调整上边距 */
	}

	button:active {
		opacity: 0.9;
	}

	.return {
		color: #2196F3;
		font-size: 14px;
		text-align: center;
		/*margin-top: 20px;*/
		/* 调整上边距 */
	}

	.icon-back::before {
		content: '\003C';
		/* 使用 Unicode 字符表示小于号 */
		font-family: Arial, sans-serif;
		/* 使用一个通用字体家族 */
		margin-right: 2px;
		font-size: 20px;
		/* 调整字体大小 */
		line-height: 0;
		/* 调整行高以确保垂直居中 */
		vertical-align: middle;
		/* 确保水平居中 */
	}
</style>